﻿using System;
using System.Collections.Generic;
using System.Drawing;

namespace Petra.Gis.RenderingServices.PlanarBase 
{
  internal class PointDistanceComparer : IComparer<Point>
  {

    protected Point _refPt;




    public PointDistanceComparer(Point refPt)
    {
      _refPt = refPt;
    }




    public int Compare(Point leftPt, Point rightPt)
    {
      if (leftPt.X == rightPt.X && leftPt.Y == rightPt.Y)
        return 0;

      if (Math.Abs(leftPt.X - _refPt.X) <= Math.Abs(rightPt.X - _refPt.X) &&
          Math.Abs(leftPt.Y - _refPt.Y) <= Math.Abs(rightPt.Y - _refPt.Y))
        return -1;

      if (Math.Abs(leftPt.X - _refPt.X) >= Math.Abs(rightPt.X - _refPt.X) &&
          Math.Abs(leftPt.Y - _refPt.Y) >= Math.Abs(rightPt.Y - _refPt.Y))
        return 1;

      return 0;
    }
  }
}
